#include "ActionDie.h"
#include "Memory.h"
#include "NPCEntity.h"


ActionDie::ActionDie()
{
                      
}

ActionDie::~ActionDie()
{
                       
}

// when a character dies he sends a message to all the allies
bool ActionDie::execute(Entity * executer)
{
	NPCEntity * realExecuter = dynamic_cast<NPCEntity*>(executer) ;
	s32 debut, fin, fps;
	IAnimatedMeshMD2* md = dynamic_cast<IAnimatedMeshMD2*>(realExecuter->getEntityMesh());
	md->getFrameLoop(EMAT_DEATH_FALLBACK,debut,fin,fps);
	realExecuter->setAnimation(debut,fin-3, false);
	realExecuter->getAttribute(std::string("eatable")) = 1.0f ; 
 
        std::map<Entity*, Memory::meminfo_t> allies = realExecuter->getMemory()->getMemoryByHostility(Hostility::ALLIED) ;
	
	std::map<Entity*,Memory::meminfo_t>::iterator it = allies.begin();
	while(it != allies.end())
	{
		std::pair<Entity*,Memory::meminfo_t> currentMemory = *it ;
        realExecuter->sendMessage(currentMemory.first,"Die"); 
        it++;
 	}  
    
    return true ;         
}


bool ActionDie::checkConditions()
{
     return true ;    
}
